const {app, BrowserWindow} =require('electron');//引入electron
let win;
let windowConfig = {
    width:800,
    height:600
};//窗口配置程序运行窗口的大小
function createWindow(){
    win = new BrowserWindow(windowConfig);//创建一个窗口
    win.loadURL(`file://${__dirname}/index.html`);//在窗口内要展示的内容index.html 就是打包生成的index.html
    win.webContents.openDevTools();  //开启调试工具
    win.on('close',() => {
        //回收BrowserWindow对象
        win = null;
    });
    win.on('resize',() => {
        win.reload();
    })
}
app.on('ready',createWindow);
app.on('window-all-closed',() => {
    app.quit();
});
app.on('activate',() => {
    if(win == null){
        createWindow();
    }
});

const path = require('path')

let exesycn = null

const createPyProc = () => {
    let script = path.join(__dirname,'VueElectron','manage.py')
    exesycn = require('child_process').spawn
    exesycn('python',[script,'runserver','127.0.0.1:8000'])
}
const exitPyProc = () => {
    exesycn = null
    let script = path.join(__dirname,'VueElectron','run.py')
    exesycn = require('child_process').exec
    exesycn(`python ${script}`)
    exesycn = null

}

app.on('ready',createPyProc)
app.on('window-all-closed',() => {
    exitPyProc()
})